<?php

namespace App\Admin\Controllers\Agents;

use App\Admin\Repositories\Withdraw;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use App\Admin\Actions\Grid\WithdrawVerifyBatch;


class WithdrawController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Withdraw(), function (Grid $grid) {
            $grid->model()->orderBy('created_at','desc');
            $grid->column('id')->sortable();
            $grid->column('agent_id');
            // $grid->column('number');
            // $grid->column('charge');
            $grid->column('提现金额')->display(function(){
                // $real = bcsub($this->number,$this->charge,2);
                return  "<div style='color:#ea5455;'>￥{$this->number}";
            });
            $grid->column('method')->using([1 => '银行卡', 2 => '微信',3=>'支付宝'])->dot([
                'default' => 'primary', // 设置默认颜色，不设置则默认为 default
                1 => 'warning',
                2 => 'success',
                3 => 'primary',
            ]);
            $grid->column('receiver');
            $grid->column('bank');
            $grid->column('no');
            $grid->column('qr')->image('http://'.$_SERVER["HTTP_HOST"].'/storage/images/agents/',100,100);
            $grid->column('state')->using([0 => '已提交', -1 => '已拒绝',1=>'已打款'])->label([
                'default' => 'primary', // 设置默认颜色，不设置则默认为 default
                1 => 'success',
                -1 => 'danger',
                0 => 'primary',
            ]);
            $grid->column('remark');
            $grid->column('created_at')->sortable();
        
            $grid->disableCreateButton();
            // $grid->disableActions();
            $grid->disableBatchDelete();
            $grid->disableDeleteButton();
            $grid->disableViewButton();
            $grid->disableEditButton();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('agent_id');
        
            });
            
            $grid->batchActions([new WithdrawVerifyBatch()]);
            $grid->tools([new WithdrawVerifyBatch()]);            

        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Withdraw(), function (Show $show) {
            $show->field('id');
            $show->field('agent_id');
            $show->field('number');
            $show->field('method');
            $show->field('state');
            $show->field('remark');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Withdraw(), function (Form $form) {
            $form->display('id');
            $form->text('agent_id');
            $form->text('number');
            $form->text('method');
            $form->text('state');
            $form->text('remark');
        
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
